package com.fourool.goodsmall.controller;

import com.fourool.goodsmall.common.Result;
import com.fourool.goodsmall.entity.GSlide;
import com.fourool.goodsmall.service.GSlideService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.fourool.goodsmall.service.SmsService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.Map;
import java.util.List;

@RestController
@RequestMapping("/common")
public class CommonController {

    @Autowired
    private GSlideService gSlideService;

    @Autowired
    private SmsService smsService;

    // 获取轮播图
    @GetMapping("/slide/list")
    public Result getSlideList() {
        List<GSlide> slides = gSlideService.getActiveSlides();
        return Result.success(slides);
    }

    // 发送短信验证码
    @PostMapping("/sms/send")
    public Result sendSms(@RequestBody Map<String, String> payload) {
        String phone = payload.get("phone");
        if (phone == null || phone.trim().isEmpty()) {
            return Result.error(400, "手机号不能为空");
        }
        return smsService.sendCode(phone);
    }
}